import numpy as np

# from src import data_helper

# def generator_batch(inputs, batch_size, vocabulary, developers, bugs_msg_all, max_sentence, active_size, window_id, is_shuffle=True):
def generator_batch(inputs, batch_size, prepared_datas, idx2bugid, data_helper, is_shuffle=True):
	inputs = np.array(inputs)
	if is_shuffle:
		indices = np.arange(len(inputs))
		np.random.shuffle(indices)
	# if is_shuffle:
	# 	for idx in range(0, len(inputs), batch_size):
	# 		excerpt = indices[idx:idx + batch_size]
	# 		if idx + batch_size > len(inputs):  # 不满足一个batch,删掉
	# 			break
	# 		# yield data_helper.data_generator_by_prepared_datas(prepared_datas, inputs[excerpt], idx2bugid)
	# 		yield np.take(prepared_datas, inputs[excerpt], 0)
	# else:
	# 	for idx in range(0, len(inputs), batch_size):
	# 		excerpt = slice(idx, idx+batch_size)
	# 		if idx + batch_size > len(inputs):  # 不满足一个batch,删掉
	# 			break
	# 		# yield data_helper.data_generator_by_prepared_datas(prepared_datas, inputs[excerpt], idx2bugid)
	# 		yield np.take(prepared_datas, inputs[excerpt], 0)
	
	for idx in range(0, len(inputs), batch_size):
		if is_shuffle:              # todo: 可以考虑把这个if提到外面去，减少做if判断的次数
			excerpt = indices[idx:idx + batch_size]
		else:
			excerpt = slice(idx, idx+batch_size)
		if idx+batch_size > len(inputs):       # 不满足一个batch,删掉
			break
		# yield data_helper.dataset_generator(vocabulary, developers, bugs_msg_all, inputs[excerpt], max_sentence, active_size, window_id) # 牺牲时间换空间
		yield data_helper.data_generator_by_prepared_datas(prepared_datas, inputs[excerpt], idx2bugid)    # 牺牲空间换时间



if __name__ == '__main__':
	# for x in generator_batch([3,2,4,5,3,2,6,4, 1], 2, is_shuffle=False):
	# 	print(x)
	pass